package com.atguigu.linklist;
public class ReverseList {
    //反转链表
    public static ListNode reverseList(ListNode head){
        if(head==null){
            return null;
        }
        if(head.next==null){
            return head;
        }
        //反转链表
        ListNode cur=head.next;
        head.next=null;
        while(cur!=null){
            ListNode node=cur.next;
            cur.next=head;
            head=cur;
            cur=node;
        }
        return head;
    }
}
